export const wxLogin = {
	async api() {
		return new Promise((resolve, reject) => {
			uni.login({
				success(res) {
					console.log('官网返回login', res);
					// 通过uni.login获取到临时登录凭证code
					if (res.code) {
						resolve(res.code);
					} else {
						reject(new Error('登录失败！' + res.errMsg));
					}
				},
				fail(err) {
					console.error('uni.login 失败', err);
					reject(err);
				}
			});
		});
	}
};
export const WxGetPhone = {
	async api(e) {
		return new Promise((resolve, _reject) => {
			uni.request({
				url: "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" +
					appid.value + "&secret=" + appsecret.value,
				success: (res) => {
					console.log('res.data.access_token',res.data)
					uni.request({
						url: "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" +
							res.data.access_token,
						method: 'POST',
						data: {
							code: e.detail.code
						},
						success: (res) => {
							console.log("用户手机号获取");
							console.log(res);
							console.log("用户手机号获取=>>>",e.detail.code);
							resolve(res.data.phone_info.phoneNumber);
						},
						fail: function(res) {
							console.log('错误了' + res); //发送失败回调，可以在这里了解失败原因
						},
					})
				},
				fail: function(res) {
					console.log('失败了' + res); //发送失败回调，可以在这里了解失败原因
				},

			})
		})
	}
}